package SmartHome.observers;

import java.util.*;

public class Sensor implements Subject{
    private final List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String message) {
        for (Observer observer : observers) {
            observer.update(this,message);
        }
    }

    public void detectTemperatureChange(String message) {
        System.out.println("Sensor: 检测到-->" + message);
        notifyObservers(message);
    }

}
